var async = require('async');
/* eslint-disable camelcase */
var renderEngin = require('../common/renderEngin');
exports.ent_auth = function (req, res) {
    use(['public/javascripts/ent_auth/init.js', 'public/javascripts/service/ent_authService.js'], function (PageComponent, ent_authService) {
        var storage = {};
        ent_authService.checkIsAuth({ headers: req.headers }, function (response) {
            if (response.errorCode === 0) {
                switch (response.data) {
                    case 0:
                        ent_authService.getAuthInfo({ headers: req.headers }, function (responseInfo) {
                            storage.authInfo = responseInfo.data;
                            PageComponent = React.createFactory(PageComponent);
                            renderEngin.call(res, 'ent_auth', PageComponent, storage);
                        });
                        break;
                    case 1:
                        storage.authSubmited = true;
                        PageComponent = React.createFactory(PageComponent);
                        renderEngin.call(res, 'ent_auth', PageComponent, storage);
                        break;
                    case 2:
                        storage.authPassed = true;
                        PageComponent = React.createFactory(PageComponent);
                        renderEngin.call(res, 'ent_auth', PageComponent, storage);
                        break;
                    default:
                        res.redirect('/login');
                        break;
                }
            } else {
                res.redirect('/login');
            }
        });
    });
};
